package com.tqz.dao;

import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;


import java.sql.SQLException;

public class NewsSerch_user {
	
	public boolean checkUser(String name,String pwd)
	{
		Connection connection=DBHlper.getConnection();
		PreparedStatement statement=null;
		ResultSet resultSet = null;
		
		boolean check=false;
		try {
			
			statement=(PreparedStatement )connection .prepareStatement("select * from user where username=\""+name+"\" and userpwd=\""+pwd+"\"");
			resultSet =statement.executeQuery();
			System.out.println("123");
			if(resultSet.next()) {
				check=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBHlper.close(connection, statement, resultSet);
		}
		return check;
		
	}
	
	public boolean updateUser(String olduserpwd,String newuserpwd)
	{
		int affect = 0;
		boolean check=false;
		// 建立连接
		Connection connection = DBHlper.getConnection();
		// 开启会话
		PreparedStatement statement = null;
		try {
			statement = (PreparedStatement) connection
					.prepareStatement("update user set userpwd=\""+newuserpwd+"\" where userpwd=\""+olduserpwd+"\"");

			affect = statement.executeUpdate();
			System.out.println(affect);
			if(affect==0) {
				check=false;
			}else {
				check=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			// 关闭会话 和 连接
			try {
				statement.close();
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return check;
		
	}
}
